package com.ktgj.service.service.impl;

import java.util.Date;
import java.util.List;

import com.ktgj.common.core.enums.EnumHelper;
import com.ktgj.common.core.text.Convert;
import com.ktgj.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.service.mapper.OrderitemBoardingMapper;
import com.ktgj.service.domain.OrderitemBoarding;
import com.ktgj.service.service.IOrderitemBoardingService;

/**
 * 值机订单明细
Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-09-03
 */
@Service
public class OrderitemBoardingServiceImpl implements IOrderitemBoardingService
{
    @Autowired
    private OrderitemBoardingMapper orderitemBoardingMapper;

    /**
     * 查询值机订单明细

     * 
     * @param orderitemboardingId 值机订单明细
ID
     * @return 值机订单明细

     */
    @Override
    public OrderitemBoarding selectOrderitemBoardingById(Long orderitemboardingId)
    {
        return orderitemBoardingMapper.selectOrderitemBoardingById(orderitemboardingId);
    }

    /**
     * 查询值机订单明细
列表
     * 
     * @param orderitemBoarding 值机订单明细

     * @return 值机订单明细

     */
    @Override
    public List<OrderitemBoarding> selectOrderitemBoardingList(OrderitemBoarding orderitemBoarding)
    {
        return orderitemBoardingMapper.selectOrderitemBoardingList(orderitemBoarding);
    }

    /**
     * 新增值机订单明细

     * 
     * @param orderitemBoarding 值机订单明细

     * @return 结果
     */
    @Override
    public int insertOrderitemBoarding(OrderitemBoarding orderitemBoarding)
    {
        orderitemBoarding.setCreateTime(DateUtils.getNowDate());
        return orderitemBoardingMapper.insertOrderitemBoarding(orderitemBoarding);
    }

    /**
     * 修改值机订单明细

     * 
     * @param orderitemBoarding 值机订单明细

     * @return 结果
     */
    @Override
    public int updateOrderitemBoarding(OrderitemBoarding orderitemBoarding)
    {
        orderitemBoarding.setUpdateTime(DateUtils.getNowDate());
        return orderitemBoardingMapper.updateOrderitemBoarding(orderitemBoarding);
    }

    /**
     * 批量删除值机订单明细

     * 
     * @param orderitemboardingIds 需要删除的值机订单明细
ID
     * @return 结果
     */
    @Override
    public int deleteOrderitemBoardingByIds(Long[] orderitemboardingIds)
    {
        return orderitemBoardingMapper.deleteOrderitemBoardingByIds(orderitemboardingIds);
    }

    /**
     * 删除值机订单明细
信息
     * 
     * @param orderitemboardingId 值机订单明细
ID
     * @return 结果
     */
    @Override
    public int deleteOrderitemBoardingById(Long orderitemboardingId)
    {
        return orderitemBoardingMapper.deleteOrderitemBoardingById(orderitemboardingId);
    }

    /**
     * 值机订单查看详情   添加备注
     * @param orderboardingId 值机订单表   订单ID
     * @param remark   备注
     * */
    @Override
    public int updateOrderBoardingByOrderBoarding(Long orderboardingId, String remark) {
        return orderitemBoardingMapper.updateOrderBoardingByOrderBoarding(orderboardingId,remark);
    }

    /**
     * 值机订单合销
     * @param count 传入的乘机人数量
     * @param orderboardingId 值机订单详细表  订单ID
     * @return 结果
     * */
    @Override
    public int updateOrderitemBoardingByStatus(int count,Long orderboardingId) {
        /** 根据订单ID查询值机订单详细表主键   集合 */
        List<Long> orderitemBoardingList=orderitemBoardingMapper.selectOrderitemBoardingByOrderBoardingIdCount(orderboardingId);
        int result = 0;
        /** 判断传入的乘机人数量<=同一订单ID下所有数据总量 */
        if(count<=orderitemBoardingList.size()){
            /** 遍历订单详细表主键集合 */
            for (int i=0;i<count;i++){
                result = orderitemBoardingMapper.updateOrderitemBoardingByStatus(orderitemBoardingList.get(i),"30");
            }
        }
        return result;
    }
}